//
//  CampusSchoolQuestionItemModel.m
//  ShowYork
//
//  Created by hxh on 2021/3/29.
//  Copyright © 2021 hxh. All rights reserved.
//

#import "CampusSchoolQuestionItemModel.h"

@implementation CampusSchoolQuestionItemModel
- (NSString *)createDetailTimeStr{

    NSDate *date = [NSDate dataWithTimeSp:self.createTime.longValue];

    NSString *timeStr = [date getTimeWithFormatter:@"yyyy-MM-dd HH:mm:ss"];

    long currentDate = [NSDate date].timeIntervalSince1970 * 1000;
    
    NSDateFormatter *fmt_ = [[NSDateFormatter alloc] init];
    NSCalendar *calendar_ = [NSCalendar calendar];

    
    fmt_.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSDate *createdAtDate = [fmt_ dateFromString:timeStr];
    
    if (createdAtDate.isThisYear) { // 今年
        if (createdAtDate.isToday) { // 今天
            NSDate *nowDate = [NSDate dataWithTimeSp:currentDate];
            NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
            NSDateComponents *cmps = [calendar_ components:unit fromDate:createdAtDate toDate:nowDate options:0];
            if (cmps.hour >= 1) { // 时间间隔 >= 1小时
                return [NSString stringWithFormat:@"%zd小时前", cmps.hour];
            }else{
                if (cmps.minute <= 0) {
                    return @"刚刚";
                }
                return [NSString stringWithFormat:@"%zd分钟前", cmps.minute];
            }
        }else {
            fmt_.dateFormat = @"M-d";
            NSString *monthDay = [fmt_ stringFromDate:createdAtDate];
            return [NSString stringWithFormat:@"%@",monthDay];
        }
    } else {
        fmt_.dateFormat = @"yyyy-M-d";
        NSString *dataStr = [fmt_ stringFromDate:createdAtDate];
        return [NSString stringWithFormat:@"%@",dataStr];
    }
}
@end
